#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,p,ans;
int main(){
    cin>>a>>b>>p;
    while(b){
    	if(b&1)ans=(ans+a)%p;
    	b>>=1;a=2*a%p;
	}
    cout<<ans<<endl;
    return 0;
}
